﻿@{
    ViewBag.Title = "Form";
    Layout = "~/Views/Shared/_Form.cshtml";
}
<form id="form1">
    <div style="padding-top: 20px; margin-right: 20px;">
        <table class="form">
            <tr>
                <th class="formTitle">联系人<span style="color:red">*</span></th>
                <td class="formValue">
                    <input id="ContactName" name="ContactName" type="text" class="form-control required" placeholder="请录入联系人" />
                </td>
                <th class="formTitle">联系手机<span style="color:red">*</span></th>
                <td class="formValue">
                    <input id="Phone" name="Phone" type="text" class="form-control required" placeholder="请录入联系手机" />
                </td>
            </tr>
            <tr>
                <th class="formTitle">联系电话</th>
                <td class="formValue">
                    <input id="Mobile" name="Mobile" type="text" class="form-control" placeholder="请录入联系电话" />
                </td>
                <th class="formTitle">邮箱</th>
                <td class="formValue">
                    <input id="Email" name="Email" type="text" class="form-control" placeholder="请录入联系邮箱" />
                </td>
            </tr>
            <tr>
                <th class="formTitle">角色</th>
                <td class="formValue">
                    <select id="RoleId" name="RoleId" class="form-control required">
                        <option value="2002">场地联络人</option>
                        <option value="2001">场地管理员</option>
                    </select>
                </td>
            </tr>
        </table>
    </div>
</form>
<script>
    var keyValue = $.request("keyValue");
    $(function () {
        if (keyValue) {
            $.ajax({
                url: "/SiteManage/Supplier/GetContactJson",
                data: { keyValue: keyValue },
                dataType: "json",
                async: false,
                success: function (data) {
                    $("#form1").formSerialize(data);
                    $('#RoleId').val(data.RoleId);
                }
            });
        }
    });

    function submitForm() {
        if (!$('#form1').formValid()) {
            return false;
        }
        if (isPoneAvailable($('#Phone'))) {
            $.submitForm({
                url: "/SiteManage/Supplier/SubmitContactForm?keyValue=" + keyValue,
                param: $("#form1").formSerialize(),
                success: function () {
                    $.currentWindow().$("#gridList").trigger("reloadGrid");
                }
            })
        } else {
            alert('手机号不符合规律');
            return false;
        }
    }

    function isPoneAvailable($poneInput) {
        var myreg = /^(13[0-9]{9})|(18[0-9]{9})|(14[0-9]{9})|(17[0-9]{9})|(15[0-9]{9})$/;
        if (!myreg.test($poneInput.val())) {
            return false;
        } else {
            return true;
        }
    }

</script>